﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DAL;
using DTO;

namespace BUS
{
    public class KHACH_HANGBUS
    {
        KHACH_HANGDAL kh = new KHACH_HANGDAL();
        public void KhachHang_Them(KHACH_HANG k)
        {
            kh.KhachHang_ThemDuLieu(k);
        }

        public void KhachHang_Sua(KHACH_HANG k)
        {
            kh.KhachHang_SuaDuLieu(k);
        }

        public void KhachHang_Xoa(int id)
        {
            kh.KhachHang_XoaDuLieu(id);
        }

        public static KhachHangCollection KhachHang_LayTatCaCSDL()
        {
            int t = 0;
            KHACH_HANGDAL dh = new KHACH_HANGDAL();
            return dh.Get("where 1=1", 0, 1000, KhachHangColumns.MA_KH.ToString(), "DESC", out t);
        }
        
        public static KHACH_HANG GetByID(int iD)
        {
            int t = 0;
            KHACH_HANGDAL dh = new KHACH_HANGDAL();
            KhachHangCollection collection = dh.Get("where " + KhachHangColumns.MA_KH.ToString() + " = " + iD.ToString(), 0, 0,
            KhachHangColumns.MA_KH.ToString(), "ASC", out t); // cần hiểu chổ này
            if (collection.Count == 1)
                return collection[0];
            return null;
        }

        public static string GetCha(int makhachhang)
        {
            int t = 0;
            KHACH_HANGDAL dh = new KHACH_HANGDAL();
            KhachHangCollection collection = dh.Get("where " + KhachHangColumns.MA_KH.ToString() + " = " + makhachhang.ToString(), 0, 0,
            KhachHangColumns.MA_KH.ToString(), "ASC", out t);
            if (collection.Count == 1)
                return collection[0].TenKhachHang.ToString();
            return null;
        }
        public static KHACH_HANG GetByEmail(string email)
        {
            KHACH_HANGDAL khDAL = new KHACH_HANGDAL();
            return khDAL.GetByEmail(email);
        }
    }
}
